from typing import List

from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.role.services import RoleBusinesses



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    role_id: int = Body(0, alias='roleId', title="roleId", description='roleId')
    remark: str = Body(None, alias='remark', title="name", description='name')
    role_name: str = Body(None, alias='roleName', title="roleName", description='roleName')
    is_trusted: bool = Body(True, alias='isTrusted', title="is_trusted", description='是否显示')
    _vts: str = Body(None, alias='_vts', title="_vts", description='_vts')
    create_time: str = Body('now()', alias='creatTime', title="creatTime", description='loginName')
    update_time: str = Body('now()', alias='updateTime', title="updateTime", description='loginName')

class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SystemRoleAddController(IController):

    def business_login(self):
        pass
        if self.schema_param.role_id == 0:
            self.schema_param.role_id = RoleBusinesses.get_sys_role_id_max_id() + 1

        result = RoleBusinesses.add_sys_role_info(**self.schema_param.dict(exclude={'is_trusted','_vts'}))
        if result:
            self.response_msg = '添加成功'
        else:
            self.response_ok = False
            self.response_msg = '添加失败'
            return None

        return None
